package net.nohaven.proj.javeau.fs.real;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Date;

import net.nohaven.proj.javeau.fs.exceptions.EntityNotFoundException;
import net.nohaven.proj.javeau.fs.model.FSFile;

public final class RFSFile implements FSFile {
	protected File file;

	public RFSFile(String path) throws EntityNotFoundException {
		this(new File(path));
	}

	public RFSFile(File file) throws EntityNotFoundException {
		if (!file.exists() || !file.isFile())
			throw new EntityNotFoundException("Path is not a file");
		this.file = file;
	}

	public InputStream getContent() throws EntityNotFoundException {
		try {
			return new FileInputStream(file);
		} catch (FileNotFoundException e) {
			throw new EntityNotFoundException(e.getMessage());
		}
	}

	public long getSize() {
		return file.length();
	}

	public boolean canWrite() {
		return file.canWrite();
	}

	public Date getModificationDate() {
		return new Date(file.lastModified());
	}

	public String getName() {
		return file.getName();
	}
}
